@extends('layouts.admin.application')
@section('css')
    <link rel="stylesheet" href="/ace/assets/css/daterangepicker.css">
@endsection
@section('content')
    <div class="main-content">

        <div class="breadcrumbs" id="breadcrumbs">
            <ul class="breadcrumb">
                <li><i class="icon-home home-icon"></i><a href="#">首页</a></li>
                <li>订单详情</li>
            </ul>
        </div>

        @include('layouts.partials._flash')

        <div class="col-xs-12">
            <div class="uc-box uc-main-box">
                <div class="uc-content-box order-view-box">
                    <div class="box-hd">
                        <h1 class="title">订单详情
                            <small>请谨防钓鱼链接或诈骗电话</small>
                        </h1>
                        <div class="more clearfix">
                            <h2 class="subtitle">订单号：
                                <span class="tag tag-subsidy">{{$order['id']}}</span>
                            </h2>
                        </div>
                    </div>
                    <div class="box-bd">
                        <div class="uc-order-item uc-order-item-finish">
                            <div class="order-detail">
                                <div class="order-summary">

                                    <div class="order-status">
                                        {{order_status($order->status)}}

                                        <div style="float:right;margin-right:10px;">
                                            {{--配货--}}
                                            @if($order->status == 2)
                                                <a href="javascript:;" class="am-btn am-btn-secondary am-radius" id="picking">配货</a>
                                            @endif

                                            {{--发货--}}
                                            @if(in_array($order->status, [3, 4]))
                                                <form style="display: inline-block">

                                                    <label>
                                                        <select class="dataTables_filter" id="express_id"
                                                                style="width: 180px;">

                                                            @foreach($expresses as $express)
                                                                <option value="{{$express->id}}"
                                                                        @if($order->express_id == $express->id) selected @endif>
                                                                    {{$express->name}}
                                                                </option>
                                                            @endforeach

                                                        </select>
                                                    </label>
                                                    <label><input type="text" id="express_code"
                                                                  value="{{$order->express_code}}"
                                                                  aria-controls="sample-table-2">
                                                    </label>

                                                    <button type="button" class="am-btn am-btn-warning"
                                                            id="shipping" data-status="{{$order->status}}">
                                                        @if($order->status == 3)
                                                            发货
                                                        @endif
                                                        @if($order->status == 4)
                                                            修改快递信息
                                                        @endif
                                                    </button>

                                                    @if($order->status == 5)
                                                        <button type="button" class="am-btn am-btn-success" id="finish">
                                                            交易成功
                                                        </button>
                                                    @endif
                                                </form>
                                            @endif
                                        </div>
                                    </div>

                                    <div class="order-progress">
                                        <ol class="progress-list clearfix">
                                            <li class="step step-first">
                                                <div class="progress"><span class="text">下单</span></div>
                                                <div class="info">{{$order->created_at->format("Y年m月d日 H:i")}}</div>
                                            </li>
                                            <li class="step @if($order->status == 2) step-done @endif">
                                                <div class="progress"><span class="text">付款</span></div>
                                                <div class="info">{{ time_format("Y年m月d日 H:i", $order->pay_time) }}</div>
                                            </li>
                                            <li class="step @if($order->status == 3) step-done @endif">
                                                <div class="progress"><span class="text">配货</span></div>
                                                <div class="info">{{ time_format("Y年m月d日 H:i", $order->picking_time) }}</div>
                                            </li>
                                            <li class="step @if($order->status == 4) step-done @endif">
                                                <div class="progress"><span class="text">出库</span></div>
                                                <div class="info">{{ time_format("Y年m月d日 H:i", $order->shipping_time) }}</div>
                                            </li>
                                            <li class="step @if($order->status == 5) step-done @endif">
                                                <div class="progress"><span class="text">交易成功</span></div>
                                                <div class="info">{{ time_format("Y年m月d日 H:i", $order->finish_time) }}</div>
                                            </li>
                                        </ol>
                                    </div>


                                    {{--发货后才显示物流信息--}}
                                    @if($order->status >= 4)
                                        <div class="order-delivery order-delivery-detail">

                                            <p class="delivery-num">
                                                物流公司：@if($order->status >= 4)
                                                    <a href="{{$order->express->url}}"
                                                       target="_blank">{{$order->express->name}}
                                                        <i class="iconfont am-icon-arrow-circle-o-right"></i>
                                                    </a>
                                                @endif
                                                运单号：@if($order->status >= 4) {{$order->express_code}} @endif
                                            </p>
                                            <div class="delivery-list-wrapper">
                                                <iframe src="https://www.kuaidi100.com/?type={{ $order->express->code}}&postid={{ $order->express_code}}"
                                                        frameborder="0" width="100%" height="500"></iframe>
                                                {{--@else--}}
                                                {{--<ul class="delivery-list" data-deliver-list="115042635001301001">--}}
                                                {{--<li class="empty">暂无物流信息。</li>--}}
                                                {{--</ul>--}}
                                            </div>
                                        </div>
                                    @endif
                                    <a class="order-delivery-trigger J_deliveryTrigger has-result toggled"
                                       href="javascript: void(0);">展开物流详情 <i
                                                class="iconfont am-icon-angle-down"></i></a>

                                </div>
                                <table class="order-items-table">
                                    <tbody>
                                    @foreach($order->order_goods as $order_good)
                                        <tr>
                                            <td class="col col-thumb">
                                                <div class="figure figure-thumb">
                                                    <a target="_blank"
                                                       href="{{route('shop.good.edit', $order_good->good['id'])}}">
                                                        <img src="{{$order_good->good['image']}}" width="80"
                                                             height="80" alt="">
                                                    </a>
                                                </div>
                                            </td>
                                            <td class="col col-name">
                                                <p class="name">
                                                    <a target="_blank"
                                                       href="//item.mi.com/1151400001.html">{{$order_good->good['name']}}</a>

                                                </p>
                                            </td>
                                            <td class="col col-price">
                                                <p class="price">{{doubleval($order_good->good['price'])}}元
                                                    × {{$order_good->num}}</p>
                                            </td>
                                            <td class="col col-actions">
                                            </td>
                                        </tr>
                                    @endforeach
                                    </tbody>
                                </table>
                            </div>
                            <div id="editAddr" class="order-detail-info">

                                <h3>收货信息</h3>
                                <table class="info-table">
                                    <tbody>
                                    <tr>
                                        <th>客户编号：</th>
                                        <td>{{$order->customer->id}}</td>
                                    </tr>
                                    <tr>
                                        <th>姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：</th>
                                        <td>{{$order->customer->nickname}}</td>
                                    </tr>
                                    <tr>
                                        <th>联系电话：</th>
                                        <td><a href="tel:{{$order->address->tel}}">{{$order->address->tel}}</a></td>
                                    </tr>
                                    <tr>
                                        <th>收货地址：</th>
                                        <td>{{$order->address->province}} {{$order->address->city}} {{$order->address->area}} {{$order->address->detail}}</td>
                                    </tr>
                                    </tbody>
                                </table>
                                <div class="actions">
                                </div>

                            </div>


                            <div id="editTime" class="order-detail-info">
                                <h3>支付方式及送货时间</h3>
                                <table class="info-table">
                                    <tbody>
                                    <tr>
                                        <th>支付方式：</th>
                                        <td>{{$order->pay_type=='1' ? '微信支付' : '货到付款'}}</td>
                                    </tr>
                                    <tr>
                                        <th>送货时间：</th>
                                        <td>不限送货时间</td>
                                    </tr>
                                    </tbody>
                                </table>
                                <div class="actions">
                                </div>
                            </div>

                            <div class="order-detail-total">
                                <table class="total-table">
                                    <tbody>
                                    <tr>
                                        <th>商品总价：</th>
                                        <td><span class="num">{{doubleval($order->total_price)}}</span>元</td>
                                    </tr>
                                    <tr>
                                        <th>运&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;费：</th>
                                        <td><span class="num">{{doubleval($order->express_money)}}</span>元</td>
                                    </tr>
                                    <tr>
                                        <th>订单金额：</th>
                                        <td>
                                            <span class="num">{{doubleval($order->total_price + $order->express_money)}}</span>元
                                        </td>
                                    </tr>
                                    <tr>
                                        <th class="total">实付金额：</th>
                                        <td class="total">
                                            <span class="num">{{doubleval($order->total_price + $order->express_money)}}</span>元
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection


@section('js')
    <script>
        $(function () {
            //展开,收起
            $(".J_deliveryTrigger").click(function () {
                var $detail = $(".uc-order-item .order-delivery-detail");
                if (!$detail.is(":visible")) {
                    $(this).html('收起物流详情 <i class="iconfont am-icon-angle-up"></i>');
                } else {
                    $(this).html('展开物流详情 <i class="iconfont am-icon-angle-down"></i>');
                }
                $detail.slideToggle(300);
            });

            //配货
            $("#picking").click(function () {
                var id = "{{$order->id}}";

                $.ajax({
                    url: '{{route('shop.order.picking')}}',
                    type: 'PATCH',
                    data: {id: id},
                    dataType: 'json',
                    success: function (data) {
                        if (data.status == 0) {
                            alert(data.msg);
                            return false;
                        }
                        location.href = location.href;
                    }
                });
            });

            //修改发货信息
            $("#shipping").click(function () {
                var data = {
                    id: "{{$order->id}}",
                    status: $(this).data('status'),
                    express_code: $("#express_code").val(),
                    express_id: $("#express_id").val()
                };

                $.ajax({
                    url: '{{route('shop.order.shipping')}}',
                    type: 'PATCH',
                    data: data,
                    dataType: 'json',
                    success: function (data) {
                        if (data.status == 0) {
                            alert(data.msg);
                            return false;
                        }
                        location.href = location.href;
                    }
                });
                return false;
            });


            //交易成功
            $("#finish").click(function () {
                var data = {
                    id: "{{$order->id}}"
                };

                $.ajax({
                    url: '{{route('shop.order.finish')}}',
                    type: 'PATCH',
                    data: data,
                    dataType: 'json',
                    success: function (data) {
                        if (data.status == 0) {
                            alert(data.msg);
                            return false;
                        }
                        location.href = location.href;
                    }
                });
                return false;
            })
        })
    </script>
@endsection
